using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MVC.Models.Database;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace MVC.Controllers
{
    [Route("[controller]")]
    public class NewsController : Controller{
        private readonly LifengContext _context;
        public NewsController(LifengContext context)
        {
            _context = context;
        }
        // [Route("/AboutUs")]
        public IActionResult Index()
        {
            // 查询所有文章
            var article = _context.Articles.ToList();
            // 将查询结果传递给视图
            ViewData["Articles"] = article;
            return View();
        }

        [Route("/News/{id}")]
        public IActionResult Detail(int id)
        {
            // 查询指定id的文章
            var article = _context.Articles.FirstOrDefault(a => a.ArticleId == id);
            // 将查询结果传递给视图
            ViewData["Article"] = article;
            return View("~/Views/News/article.cshtml");
        }
    }
}